<template>
  <div class="menu no-drag">
    <SwitcherOutlined @click="reloadWin" />
    <MinusOutlined @click="handleMin" />
    <FullscreenExitOutlined @click="handleRestore"
                            v-if="maximize" />
    <BorderOutlined v-else
                    @click="handleMax" />
    <CloseOutlined @click="handleClose" />
  </div>
</template>

<script>
import { SwitcherOutlined, MinusOutlined, FullscreenExitOutlined, BorderOutlined, CloseOutlined } from '@ant-design/icons-vue';
import { ref } from 'vue';
const { remote, ipcRenderer } = window.require('electron')
export default {
  components: {
    SwitcherOutlined,
    MinusOutlined,
    FullscreenExitOutlined,
    BorderOutlined,
    CloseOutlined
  },
  setup() {
    let maximize = ref(false)
    const win = remote.getCurrentWindow()

    ipcRenderer.on('main-window-max', () => {
      maximize.value = true
    })
    ipcRenderer.on('main-window-restore', () => {
      maximize.value = false
    })


    const reloadWin = () => {
      win.reload()
    }
    const handleMin = () => {
      win.minimize()
    }
    const handleMax = () => {
      maximize.value = true
      win.maximize()
    }
    const handleRestore = () => {
      maximize.value = false
      win.restore()
    }
    const handleClose = () => {
      win.close()
    }


    return {
      maximize,

      reloadWin,
      handleMin,
      handleMax,
      handleRestore,
      handleClose,
    }
  }
}
</script>

<style lang='scss' scoped >
.menu {
  margin-left: 12px;
  .anticon {
    font-size: 18px;
    color: #fff;
    margin: 0 8px;
  }
}
</style>